package com.neusoft.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.neusoft.entity.BanJi;
import com.neusoft.service.BanjiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Banji)表控制层
 *
 * @author makejava
 * @since 2020-06-08 11:11:33
 */
@RestController
@RequestMapping("banji")
public class BanjiController {
    /**
     * 服务对象
     */
    @Autowired
    private BanjiService banjiService;

    @PostMapping("insert")
    public Object insert(BanJi bean) {
        return banjiService.insert(bean);
    }

    @GetMapping("queryAll")
    public Object queryAll() {
        return banjiService.queryAll();
    }

    @GetMapping("queryById/{id}")
    @HystrixCommand(fallbackMethod = "getDefaultBanji")
    public Object queryById(@PathVariable Integer id){
        BanJi banJi = banjiService.queryById(id);
        if(banJi == null){
            throw new RuntimeException("出错，并无该id！");
        }
        return banJi;
    }

    public Object getDefaultBanji(@PathVariable Integer id){
        return new BanJi().setId(id).setName("班级不存在").setDb("No db");
    }

}